package com.tledu.car.controller;

import com.tledu.car.domain.CarList;
import com.tledu.car.service.ICarListService;
import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆列表Controller
 * 
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/car/list")
public class CarListController extends BaseController
{
    @Autowired
    private ICarListService carListService;

    /**
     * 查询车辆列表列表
     */
    @PreAuthorize("@ss.hasPermi('car:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarList carList)
    {
        startPage();
        List<CarList> list = carListService.selectCarListList(carList);
        return getDataTable(list);
    }

    /**
     * 导出车辆列表列表
     */
    @PreAuthorize("@ss.hasPermi('car:list:export')")
    @Log(title = "车辆列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarList carList)
    {
        List<CarList> list = carListService.selectCarListList(carList);
        ExcelUtil<CarList> util = new ExcelUtil<CarList>(CarList.class);
        util.exportExcel(response, list, "车辆列表数据");
    }

    /**
     * 获取车辆列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carListService.selectCarListById(id));
    }

    /**
     * 获取车辆列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:list:licence')")
    @GetMapping(value = "/licence/{licence}")
    public AjaxResult getInfoByLicence(@PathVariable("licence") String licence)
    {
        return success(carListService.selectCarListByLicence(licence));
    }

    /**
     * 新增车辆列表
     */
    @PreAuthorize("@ss.hasPermi('car:list:add')")
    @Log(title = "车辆列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarList carList)
    {
        return toAjax(carListService.insertCarList(carList));
    }

    /**
     * 修改车辆列表
     */
    @PreAuthorize("@ss.hasPermi('car:list:edit')")
    @Log(title = "车辆列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarList carList)
    {
        return toAjax(carListService.updateCarList(carList));
    }

    @PreAuthorize("@ss.hasPermi('car:list:edit')")
    @Log(title = "车辆列表", businessType = BusinessType.UPDATE)
    @PutMapping("/update1")
    public AjaxResult edit1(@RequestBody CarList carList)
    {
        return toAjax(carListService.updateCarList1(carList));
    }

    @PreAuthorize("@ss.hasPermi('car:list:edit')")
    @Log(title = "车辆列表", businessType = BusinessType.UPDATE)
    @PutMapping("/update2/{id}")
    public AjaxResult edit2(@PathVariable("id") Long id)
    {
        return toAjax(carListService.updateCarList2(id));
    }

    /**
     * 隐藏车辆列表
     */
    @PreAuthorize("@ss.hasPermi('car:list:delete')")
    @Log(title = "车辆列表", businessType = BusinessType.UPDATE)
    @PutMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable long id)
    {
        return toAjax(carListService.removeCarList(id));
    }

    /**
     * 删除车辆列表
     */
    @PreAuthorize("@ss.hasPermi('car:list:remove')")
    @Log(title = "车辆列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carListService.deleteCarListByIds(ids));
    }
}
